package com.kb5173.base.demo.dubbo;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.spring.ServiceBean;
import com.kb5173.base.demo.protocal.DemoServiceApi;

public class ServiceApiExportor {

	public static void main(String[] args) throws Exception {
		export();
		//wait()
		System.in.read();
	}

	public static void export(){
		ApplicationConfig appConfig = new ApplicationConfig();
		appConfig.setName("apiExportor");

		RegistryConfig rc = new RegistryConfig();
		rc.setAddress("115.29.28.207");
		rc.setProtocol("zookeeper");
		rc.setPort(2181);
		
		ProtocolConfig pc = new ProtocolConfig();
		pc.setPort(20882);
		//默认设置是dubbo
		pc.setName("dubbo");

		ProtocolConfig pc1 = new ProtocolConfig();
		pc1.setPort(20883);
		//默认设置是dubbo
		pc1.setName("hessian");
		List<ProtocolConfig> pcs = new ArrayList<ProtocolConfig>();
		pcs.add(pc1);
		pcs.add(pc);
		
		DemoServiceApiImpl dai = new DemoServiceApiImpl();
		ServiceBean<DemoServiceApi> service = new ServiceBean<DemoServiceApi>();
		service.setApplication(appConfig);
		service.setRegistry(rc);
		service.setInterface(DemoServiceApi.class);
		service.setRef(dai);
		service.setProtocols(pcs);
		service.export();
		
	}
}
